import * as Cesium from "cesium"
const rotateTool = function(viewer){
    this.viewer = viewer
    this.canrote = false
}
rotateTool.prototype = {
    start(position,hpr){
        var self = this
        var  nowX = 0
        var orig = Cesium.Cartesian3.fromDegrees(position.lon,position.lat)
        this.canrote = true
        var hprange = new Cesium.HeadingPitchRange(Cesium.Math.toRadians(hpr.heading), Cesium.Math.toRadians(hpr.pitch), hpr.range)
        this.viewer.scene.postRender.addEventListener(function(){
            if(self.canrote){
                nowX += 0.05
                if(nowX>179){
                    nowX = 0
                }
                hprange.heading = Cesium.Math.toRadians(nowX)
                self.viewer.camera.lookAt(orig,hprange)
            }
        })
    },
    stop(){
        this.canrote = false
    }
}
export default rotateTool
